import java.util.Scanner;

public class Solution {
    public int BitSum(int n){
        int sum = 0;
        while(n != 0){
            int t = n%10;
            sum += t*t;
            n/=10;
        }
        return sum;
    }
    public boolean isHappy(int n){
        int slow = n;
        int fast = BitSum(n);
        while(slow != fast){
            slow = BitSum(slow);
            fast = BitSum(BitSum(fast));
        }
        return slow == 1;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int num = in.nextInt();
            Solution solution1 = new Solution();
            int sum = solution1.BitSum(num);
            Solution solution2 = new Solution();
            boolean result = solution2.isHappy(sum);
            System.out.println(result);
        }
    }
}
